package com.cakeclient.clientsoap.contract;


import org.ksoap2.serialization.NullSoapObject;
import org.ksoap2.serialization.SoapObject;

public class Catalog extends ContractObject {

    public SoapArray<MenuType> menus;
    public SoapArray<ProductType> products;
    public SoapArray<ProductCategory> categories;

    public Catalog() {
    }

    @Override
    public void fill(SoapObject soapObject) {

        SoapObject menuTypes = soapObject.getPropertySafely("menus") instanceof NullSoapObject ? null : (SoapObject) soapObject.getPropertySafely("menus");
        if (menuTypes != null) {
            menus = new SoapArray<MenuType>(menuTypes.getPropertyCount(), "menus");
            for (int i = 0; i < menuTypes.getPropertyCount(); i++) {
                MenuType menuType = new MenuType();
                menuType.fill((SoapObject) menuTypes.getProperty(i));
                menus.add(menuType);
            }
        }

        SoapObject productList = soapObject.getPropertySafely("products") instanceof NullSoapObject ? null : (SoapObject) soapObject.getPropertySafely("products");
        if (productList != null) {
            products = new SoapArray<ProductType>(productList.getPropertyCount(), "products");
            for (int i = 0; i < productList.getPropertyCount(); i++) {
                ProductType productType = new ProductType();
                productType.fill((SoapObject) productList.getProperty(i));
                products.add(productType);
            }
        }

        SoapObject categoryList = soapObject.getPropertySafely("categories") instanceof NullSoapObject ? null : (SoapObject) soapObject.getPropertySafely("categories");
        if (categoryList != null) {
            categories = new SoapArray<ProductCategory>(categoryList.getPropertyCount(), "categories");
            for (int i = 0; i < categoryList.getPropertyCount(); i++) {
                ProductCategory productCategory = new ProductCategory();
                productCategory.fill((SoapObject) categoryList.getProperty(i));
                categories.add((productCategory));
            }

        }
    }
}
